home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
includes
/
viewImageFunctions.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
20KB
|
421 lines
<?php
/**
* Images viewer
*
* Included by viewFunctions.php
* parameters :
* - $completeFilename : complete filename of image to view
* - $command : command
* - $extraData : [image outer width]x[image outer height]
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.1.0
*/
if(!defined('SLIDESHOW_TIMER_CONTROL_NAME')) define('SLIDESHOW_TIMER_CONTROL_NAME','slideShowInterval');
/**
* Return an image's rotation, from user-set rotation or EXIF defined orientation
* In case of auto Exif rotation, put rotation in 'rot' array
*
* @param string $cfn
* @return int 0,90,180,270
*/
function getRotation($cfn){
if((cfFileExtension($cfn)=='jpg'||cfFileExtension($cfn)=='jpeg') && cfRGetVar('rot',$cfn,false,null)===null && cfGGetVar('EXIFAutoRotation')){
if($r=cfArrayItem(@exif_read_data($cfn),'Orientation')){
if($r==3) $rot=180;
if($r==6 || $r==7) $rot=90;
if($r==5 || $r==8) $rot=270;
if(isset($rot)){
cfRSetVar('rot',$cfn,$rot);
return $rot;
}
}
}
return (int)cfRGetVar('rot',$cfn);
}
/**
* @desc return image width and height
*
* @param string $completeFilename : image filename
* @return array(width, height)
*/
function getImageDimensions($completeFilename){
if(cfFileExtension($completeFilename)=='itc'){
if(!($sourceImage=@imagecreatefromstring(substr(file_get_contents($completeFilename),500)))) return array(400,300);
$sourceWidth=imagesx($sourceImage); $sourceHeight=imagesy($sourceImage);
$sourceImage=null;
}
elseif(cfFileExtension($completeFilename)=='itc2'){
if(!($sourceImage=@imagecreatefromstring(substr(file_get_contents($completeFilename),492)))) return array(400,300);
$sourceWidth=imagesx($sourceImage); $sourceHeight=imagesy($sourceImage);
$sourceImage=null;
}
else list($sourceWidth, $sourceHeight, $type, $attr) = @getimagesize($completeFilename);
if(!$sourceWidth) $sourceWidth=120;
if(!$sourceHeight) $sourceHeight=120;
// iPhone: limit output size
if(cfBGetVar('name')=='iPhone'){
list($sourceWidth,$sourceHeight)=cfThumbnailDimensions($sourceWidth,$sourceHeight,480*3,320*3,false);
}
return array($sourceWidth,$sourceHeight);
}
/**
* @desc return previous or next file in a directory
*
* @param string $completeFilename : path and file name of current file
* @param string $position : position of searched file : 'next' or 'previous'
* @param string $fileType : optional : restrict search to files whose (left part of) mime type is $fileType
* @param string $fileExt : optional : restrict search to files whose extension is $fileExt
* @param int $postion: optional: return position of completeFilename in list
* @param int $total : optional: return total number of files (images)
* @return string : complete filename of previous or next file
*/
function findContiguousFile($completeFilename,$position,$fileType=false, $fileExt=false, &$postion=null, &$total=null){
static $files=false;
if($position!='next' && $position!='previous') return $completeFilename;
// Get file's directory
if(cfSharedMode('list') && @$_POST['data1']=='*resourceBasePath*') $dir='*resourceBasePath*/'; else $dir=cfDirName($completeFilename);
// Get dir's images (only process once)
if(!$files) {
$files=efGetDirContent($dir,false,false,'image',true,array('noExtra'=>1));
foreach ($files as $k=>$v) if(!is_array($v)) unset($files[$k]);
}
$total=count($files);
if(count($files)<2) return $completeFilename;
// Browse files
reset($files);
$elt=current($files);
$postion=0;
while($elt!==false) {
$postion++;
// Current element found
if($elt['completeFileName']==$completeFilename){
// Look for next
if($position=='next'){
if($elt=next($files)) return $elt['completeFileName'];
$elt=reset($files);
return $elt['completeFileName'];
}
// Look for previous
else{
if($elt=prev($files)) return $elt['completeFileName'];
$elt=end($files);
return $elt['completeFileName'];
}
}
$elt=next($files);
}
return $completeFilename; // should'nt happend
}
/**
* @desc Return true if image has EXIF data
*
* @param string $completeFilename: name and path of image
* @return boolean
*/
function hasExifData($completeFilename){
$exif=@exif_read_data($completeFilename);
if(!$exif || !isset($exif['SectionsFound']) || !$exif['SectionsFound']) return false;
return true;
}
// If required by another script for functions, don't execute
if(isset($requiredScript)) return ;
/*
***************************************************************************************************************************
* Process POST commands
***************************************************************************************************************************
*/
if(cfIsAsync()){// async request
cfAsyncHeader();
$output='';
$skipImages=0; // !=0 if user pressed several times next or prev buttons
$resetImgDims=0; // 1 to reset center image position because some images have been skipped and normal animation behaviour doesn't apply anymore
if(cfCmpLeft($command,'next/')||cfCmpLeft($command,'prev/')){
$skipImages=substr($command,5);
$resetImgDims=1;
$command=substr($command,0,4);
}
if($command=="fullsize") cfRSetVar('fullSizeView',true); // Set full-size view
elseif($command=="resized") cfRSetVar('fullSizeView',false); // Set resized view
elseif($command=="toggleSlideshow") {cfRSetVar('slideshow',!cfRGetVar('slideshow')); cfRSetVar('fullSizeView',false);} // Toggle slideshow & set resized view
elseif($command=="rotate0") cfRSetVar('rot',$completeFilename,0);
elseif($command=="rotate90") cfRSetVar('rot',$completeFilename,90);
elseif($command=="rotate180") cfRSetVar('rot',$completeFilename,180);
elseif($command=="rotate270") cfRSetVar('rot',$completeFilename,270);
// Show EXIF data in tooltip
if($command=='getFileInfo') {
require(INCLUDE_DIR.'fileInfoFunctions.php');
$getThumbnail=0;
echo cfAsyncXMLJSaction('tooltipSetProperties('.fiPHPArrayToJSArray(fiGetInfo($completeFilename,$getThumbnail)).')');
}
if($command=='next' || $command=='prev' || $command=='view' || substr($command,0,3)=='rot'){
if($command=='prev' || $command=='next') {
while(1){
if($skipImages<0 || $command=='prev'){
$completeFilenameNext=$completeFilename;
$completeFilename=findContiguousFile($completeFilename,'previous','image');
$completeFilenamePrev=findContiguousFile($completeFilename,'previous','image',false,$filePos,$fileTotal);
if(!$skipImages) break;
$skipImages++;
}
else{
$completeFilenamePrev=$completeFilename;
$completeFilename=findContiguousFile($completeFilename,'next','image');
$completeFilenameNext=findContiguousFile($completeFilename,'next','image',false,$filePos,$fileTotal);
if(!$skipImages) break;
$skipImages--;
}
}
}
if($command=='view' || substr($command,0,3)=='rot'){
$completeFilenamePrev=findContiguousFile($completeFilename,'previous','image');
$completeFilenameNext=findContiguousFile($completeFilename,'next','image',false,$filePos,$fileTotal);
}
// Log content access
if($command=='next' || $command=='prev' || $command=='view') cfLogContentAccess($completeFilename);
// Set previous image dimensions
if($command!='next' && substr($command,0,3)!='rot'){
list($sourceWidth, $sourceHeight) = getImageDimensions($completeFilenamePrev);
if(($rot=getRotation($completeFilenamePrev))=='90' || $rot=='270') cfSwap($sourceWidth, $sourceHeight);
$output.=cfAsyncXMLJSaction('pfw='.$sourceWidth.';pfh='.$sourceHeight.';pTitle="'.cfUTF8Encode(cfFileWithoutExtension(basename($completeFilenamePrev))).'";');
}
// Set next image dimensions and title
if($command!='prev' && substr($command,0,3)!='rot'){
list($sourceWidth, $sourceHeight) = getImageDimensions($completeFilenameNext);
if(($rot=getRotation($completeFilenameNext))=='90' || $rot=='270') cfSwap($sourceWidth, $sourceHeight);
$output.=cfAsyncXMLJSaction('nfw='.$sourceWidth.';nfh='.$sourceHeight.';nTitle="'.cfUTF8Encode(cfFileWithoutExtension(basename($completeFilenameNext))).'";');
}
// Set current image properties
if($command=='view' || substr($command,0,3)=='rot' || $resetImgDims){
list($sourceWidth, $sourceHeight) = getImageDimensions($completeFilename);
if(($rot=getRotation($completeFilename))=='90' || $rot=='270') cfSwap($sourceWidth, $sourceHeight);
}
else $sourceWidth=$sourceHeight=0;
// Set (next) previous image template URL
$output.=cfAsyncXMLJSaction('imgURLPrev="'.cfExtImage($completeFilenamePrev,'<WIDTH>','<HEIGHT>',true,(int)cfRGetVar('rot',$completeFilenamePrev)).'";');
// Set current image template URL
$output.=cfAsyncXMLJSaction('imgURL="'.cfExtImage($completeFilename,'<WIDTH>','<HEIGHT>',true,'<ANGLE>').'";rot='.(int)cfRGetVar('rot',$completeFilename));
// Set current image full size URL
if(cfBGetVar('name')=='iPhone'){
list($width, $height) = getImageDimensions($completeFilename);
$output.=cfAsyncXMLJSaction('imgURLFull="'.cfExtImage($completeFilename,$width,$height,true,'<ANGLE>').'";');
}
else
$output.=cfAsyncXMLJSaction('imgURLFull="'.cfExtImage($completeFilename,0,0,true,'<ANGLE>').'";');
// Set (next) next image template URL
$output.=cfAsyncXMLJSaction('imgURLNext="'.cfExtImage($completeFilenameNext,'<WIDTH>','<HEIGHT>',true,(int)cfRGetVar('rot',$completeFilenameNext)).'";');
$output.=cfAsyncXMLJSaction('setImageData("'.cfUTF8Encode(cfFileWithoutExtension(basename($completeFilename))).'","'.cfUTF8Encode(basename($completeFilename)).'",'.(int)$sourceWidth.','.(int)$sourceHeight.','.(int)$filePos.','.(int)$fileTotal.');');
if ($command=='next') $output.=cfAsyncXMLJSaction('nextProceed('.$resetImgDims.')');
elseif ($command=='prev') $output.=cfAsyncXMLJSaction('prevProceed('.$resetImgDims.')');
elseif ($command=='view') $output.=cfAsyncXMLJSaction('loadProceed(true)');
elseif (substr($command,0,3)=='rot') $output.=cfAsyncXMLJSaction('loadProceed(false)');
if(cfRGetVar('showExifData') &&($command!='rot'))
$output.=cfAsyncXMLJSaction('showExifHover('.((hasExifData($completeFilename))?'1':'0').')');
}
echo $output;
echo cfAsyncFooter();
exit;
}
/*
***************************************************************************************************************************
* Display page
***************************************************************************************************************************
*/
cfInsertHEAD(false);
if(cfBGetVar('name')=='iPhone') echo '<meta name="viewport" id="viewport" content="width=device-width, height=500, initial-scale=1.0, user-scalable='.((cfRGetVar('fullSizeView')=='full')?'yes':'no').'">';
// Include explorer.js scripts (for dl() function)
echo cfScriptLink('explorer.js');
// Include view image scripts
echo cfScriptLink('viewImage.js');
// Set JS vars
?>
<script type="text/javascript">
var adaptViewport=<?php if(cfBGetVar('name')=='iPhone') echo '1'; else echo '0'; ?>;
var defaultTitle="<?php echo str_replace('"','\\"',cfUTF8Encode(cfRGetVar('name')));?>";
var slideshow=<?php echo ((cfRGetVar('slideshow'))?'1':'0'); // 1 in slideshow mode, 0 in normal viewing mode?>;
var sTimeout=<?php echo ((cfRGetVar('slideShowInterval')!=0)?cfRGetVar('slideShowInterval')*1000:DEFAULT_SLIDESHOW_INTERVAL*1000);?>;
var imgURL; var imgURLFull; var imgURLPrev; var imgURLNext; <?php // Template URLs of current, full-size, prev, next images ?>
var imgFullSizeLoaded=<?php echo ((cfRGetVar('fullSizeView'))?'1':'0');?>;
var zoom="<?php echo ((cfRGetVar('fullSizeView'))?'full':'resized');?>";
var zoomSteps=<?php if(cfBGetVar('name')=='iPhone') echo 1; elseif(cfBGetVar('fastAnim')) echo 5; else echo 3;?>;
var slideSteps=<?php if(cfBGetVar('fastAnim')) echo 15; else echo 7;?>;
var emptySrc="<?php echo outIcon('v');?>";
var reducedPreview=<?php echo (cfRGetVar('reducedPreview')?1:0);?>;
var bDrag=<?php echo (cfBGetVar('drag')?1:0);?>;
var SLIDESHOW_TIMER_CONTROL_NAME="<?php echo SLIDESHOW_TIMER_CONTROL_NAME;?>";
var secCaption="<?php echo cfCaption('genSeconds');?>";
</script>
<style type="text/css">
.blackFrame{background:black;padding:0;margin:0}
.imageView {position:absolute;margin:0px;overflow:hidden;width:1px;height:1px}
.blackFrame .imageView{background:#050505;border:1px solid #151515}
</style>
</head>
<body class="iframeBody" id="imageFrameBody" style="margin:0px;overflow:hidden<?php if(cfRGetVar('slideshow')) echo ';background:black';?>" onkeydown="keyPressed(event)" onload="init()" onorientationchange="updateOrientation()">
<?php
echo cfScriptLink('wz_dragdrop.js');
// Standard com form
outInsertStandardComForm($_SERVER['PHP_SELF'],cfUTF8Encode(cfDirName(cfResourceRelativePath($completeFilename))),cfUTF8Encode(basename($completeFilename)),'view');
echo outDivFrame(((cfRGetVar('slideshow'))?'blackFrame':'frame1'),'id="frame1" onclick="bgClick()"','margin:0;padding-left:0;padding-right:0;padding-bottom:0;text-align:center;overflow:hidden;border:0px solid red;');
$l='';$c='';$r='';
/**
***************************************************************************************************************************
* TOP Controls
***************************************************************************************************************************
*/
// Normal display
// Left part
// Download button
if(cfRGetVar('downloadShortcut')) $l.=outButton(false,'javascript:dl(document.comForm.data2.value)',outIcon('dl'),cfCaption('genDownload'));
// Multiple download button
if(cfRGetVar('multipleDownloadAllowed') && cfTGetVar('frames')) $l.=outButton('',"javascript:mAddOpener(document.comForm.data2.value)", outIcon('mdl'),cfCaption('explorerMultipleDownloadAdd'));
// Previous image
if(cfBGetVar('drag')) $l.=' '.outButton('','javascript:buttonPrev()',outIcon('prev'),cfCaption('explorerPrevious'),false);
// Toogle to slide show mode
$l.='<div id="slideShowStartBt" style="display:inline">'. outButton(false,'javascript:toggleSlideshow(1)',outIcon('sshow'),cfCaption('explorerSlideShowStart')).'</div>';
// Next image
if(cfBGetVar('drag')) $l.=outButton('','javascript:buttonNext()',outIcon('next'),cfCaption('explorerNext'),false);
// Center part
// Title
$c.=(($l)?' ':'').'<span style="white-space:nowrap;overflow:hidden" id="viewImageTitle">'.cfUTF8Encode(cfFileWithoutExtension(basename($completeFilename))).'</span>';
// hidden Filename
$c.='<span style="display:none" id="viewedFile">'.cfUTF8Encode(basename($completeFilename)).'</span>';
// Right part
// Rotate and full/normal size buttons
if(!cfRGetVar('noImageRotation')){
$r.=outButton(false,'javascript:rotateLeft()',outIcon('rotL'),cfCaption('viewRotateLeft'));
$r.=outButton(false,'javascript:rotateRight()',outIcon('rotR'),cfCaption('viewRotateRight'));
}
$r.=outButton('','javascript:winMe.restore()',outIcon('normalSize'),false,'normalSizeButton','style="display:none;"');
// Insert frame header (title + buttons)
if(cfBGetVar('name')=='iPhone') echo '<div class="frame1Header" id="headerNormal" style="display:none">'.$c.$r.$l.'</div>';
elseif(cfTGetVar('compactDisplay')) echo '<div class="frame1Header" id="headerNormal" style="margin-bottom:0px'.((cfRGetVar('slideshow'))?';display:none':'').'">'.$c.$r.$l.'</div>';
else echo outFrameHeaderTable('frame1Header',$l,$r,'id="headerNormal"','margin-bottom:0px;'.((cfRGetVar('slideshow'))?'display:none':''),$c);
// Slideshow view
echo '<div id="headerSlideshow" style="position:absolute;z-index:2000;left:0;text-align:left;'.((cfRGetVar('slideshow'))?'':'top:-1000px').'">';
echo outButton(false,'javascript:toggleSlideshow(0)',outIcon('sshowStop'),cfCaption('explorerSlideShowStop')); // Toggle back to normal view
echo outButton('','javascript:winMe.restore()',outIcon('normalSize'),false,'normalSizeButton2','style="display:none;"');
echo outButton(false,'javascript:slideshowPause()' ,outIcon('pause'),false,'slideShowPauseBt');
echo outButton(false,'javascript:slideshowResume()',outIcon('sshow'),false,'slideShowResumeBt','style="display:none"');
if(!cfRGetVar('slideShowInterval')) cfRSetVar('slideShowInterval',4);
echo outControl(SLIDESHOW_TIMER_CONTROL_NAME,dataList,cfRGetVar('slideShowInterval'),array(1,2,3,4,5,10,15,30),'slider',array('width'=>'9em'));
echo '</div>';
/**
***************************************************************************************************************************
* Images
***************************************************************************************************************************
*/
?>
<div style="width:100%;overflow:hidden;position:relative;text-align:left" id="scrollDiv">
<div id="imgDiv" class="imageView" onclick="toggleZoom()">
<img id="img" src="<?php echo outIcon('v');?>" onload="loaded(this.id)" onerror="loaded(this.id)" style="visibility:hidden" alt="">
</div>
<div id="imgNextDiv" class="imageView" onclick="toggleZoom()">
<img id="imgNext" onload="loaded(this.id)" onerror="loaded(this.id)" alt="" title="">
</div>
<div id="imgPrevDiv" class="imageView" onclick="toggleZoom()">
<img id="imgPrev" onload="loaded(this.id)" onerror="loaded(this.id)" alt="" title="">
</div>
<img id="imgCacheFull" alt="" onload="loaded(this.id)" style="visibility:hidden;position:absolute">
<img id="imgCacheNext" alt="" onload="loaded(this.id)" style="visibility:hidden;position:absolute">
<img id="imgCachePrev" alt="" onload="loaded(this.id)" style="visibility:hidden;position:absolute">
<img id="loading" style="position:absolute;top:3px;left:3px;display:none;z-index:1000;" src="<?php echo outIcon('loadingBlack');?>">
</div>
<div id="filePosDiv" style="position:absolute;bottom:0.2em;right:0.2em;">
</div>
<?php
if((cfBGetVar('drag') && cfRGetVar('showExifData'))) {
?>
<img id="exifHover" src="<?php echo outIcon('exif');?>" style="position:absolute;bottom:0.2em;left:0.2em;display:none" onmouseover="tooltip(this)">
<script type="text/javascript">
function showExifHover(show){
dgi('exifHover').style.zIndex=dd.z+1;
if((dgi('exifHover').style.display=='none' && !show) || (dgi('exifHover').style.display!='none' && show)) return;
if(show) fade('exifHover',0,1,3); else fade('exifHover',1,0,3);
}
function tooltipGetContent(nodeId){
submitFrm('getFileInfo');
return '<img id="tooltipLoading" src="<?php echo outIcon('loading');?>" style="cursor:pointer">';
}
</script>
<?php
}
/**
***************************************************************************************************************************
* Scripts
***************************************************************************************************************************
*/
?>
<script type="text/javascript">
<?php
cfDragAddItem('imgDiv', '+CURSOR_HAND+INERTIA+NOBOUNCE+RESET_Z');
cfDragAddItem('imgPrevDiv','+CURSOR_HAND+INERTIA+NOBOUNCE+RESET_Z');
cfDragAddItem('imgNextDiv','+CURSOR_HAND+INERTIA+NOBOUNCE+RESET_Z');
cfDragAddItem('foo','+CURSOR_HAND+INERTIA+NOBOUNCE');
echo cfDragRegisterItems(false,false);
?>
document.body.focus();
</script>
</body>
</html>